﻿import BiDashboardMenuItem from '@/views/page_biDashboard/biDashboardMenu/BiDashboardMenuItem.vue'
export default {
  components: { BiDashboardMenuItem },
  props: ['previewUid', 'previewVisible', 'previewSettings'],
  data () {
    return {
      loading: false,
      formData: null,
      previewDashboardVisible: false
    }
  },
  methods: {
    // 初始化页面
    initPage () {
      if (this.previewUid) {
        this.loading = true
        this.getBasicInfoByUid(this.previewUid)
      } else {
        if (this.previewSettings) {
          this.formData = JSON.parse(this.previewSettings)
        } else {
          this.$message({
            message: '没有获取到页面信息',
            type: 'error'
          })
        }
      }
    },
    // 获取基础的配置信息
    getBasicInfoByUid (uid) {
      this.$get('/bi_dashboard/detail', {
        id: uid
      }).then(data => {
        let dataResult = data.data.result
        if (dataResult.code === 'success') {
          this.biDashboardInfo = dataResult.data
          if (dataResult.data.settings_json) {
            this.formData = JSON.parse(dataResult.data.settings_json)
          } else {
            this.$message({
              message: '请在仪表板页面进行页面配置',
              type: 'error'
            })
          }
        } else {
          this.$message({
            message: dataResult.msg,
            type: 'warning'
          })
        }
        this.loading = false
      })
    },
    // 关闭弹窗时
    closePreviewDialog () {
      this.$emit('closePreviewDialog')
    }
  },
  watch: {
    previewVisible: {
      handler: function (val) {
        this.previewDashboardVisible = val
        if (val) {
          this.initPage()
        }
      },
      deep: true
    }
  }
}
